
package com.sasis.dao.ibatis;

import java.util.List;

import com.sasis.dao.ibatis.BaseDaoiBATIS;
import com.sasis.model.PlaneInfo;
import com.sasis.dao.PlaneInfoDao;

import org.springframework.orm.ObjectRetrievalFailureException;

public class PlaneInfoDaoiBatis extends BaseDaoiBATIS implements PlaneInfoDao {

    /**
     * @see com.sasis.dao.PlaneInfoDao#getPlaneInfos(com.sasis.model.PlaneInfo)
     */
    public List getPlaneInfos(final PlaneInfo planeInfo) {
          return getSqlMapClientTemplate().queryForList("getPlaneInfos", planeInfo);
    }

    /**
     * @see com.sasis.dao.PlaneInfoDao#getPlaneInfo(Integer id)
     */
    public PlaneInfo getPlaneInfo(Integer id) {
        PlaneInfo planeInfo = (PlaneInfo) getSqlMapClientTemplate().queryForObject("getPlaneInfo", id);

        if (planeInfo == null) {
            throw new ObjectRetrievalFailureException(PlaneInfo.class, id);
        }

        return planeInfo;
    }

    /**
     * @see com.sasis.dao.PlaneInfoDao#savePlaneInfo(PlaneInfo planeInfo)
     */    
    public void savePlaneInfo(final PlaneInfo planeInfo) {
        Integer id = planeInfo.getId();
        // check for new record
        if (id == null) {
            id = (Integer) getSqlMapClientTemplate().insert("addPlaneInfo", planeInfo);
        } else {
            getSqlMapClientTemplate().update("updatePlaneInfo", planeInfo);
        }
        if( id == null ) {
            throw new ObjectRetrievalFailureException(PlaneInfo.class, id);
        }
    }

    /**
     * @see com.sasis.dao.PlaneInfoDao#removePlaneInfo(Integer id)
     */
    public void removePlaneInfo(Integer id) {
        getSqlMapClientTemplate().update("deletePlaneInfo", id);
    }
}
